import {defineConfig} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import {VantResolver} from '@vant/auto-import-resolver';
import {resolve} from 'path';

const define = {}
if (!["mp-weixin", "h5", "web"].includes(process.env.UNI_PLATFORM)) {
	define['global'] = null
	define['wx'] = 'uni'
}

export default defineConfig({
	plugins: [
		uni(),
		AutoImport({
			resolvers: [VantResolver()],
		}),
		define,
		Components({
			resolvers: [VantResolver()],
		}),
	],
	resolve: {
		alias: {
			'/@': resolve(__dirname, './src'),
		},
	},
	css: {
		preprocessorOptions: {
			scss: {
				api: 'modern-compiler',
				// 2. 静默 @import 弃用警告
				silenceDeprecations: ['import'],
				quietDeps: true,
			}
		}
	},
	server: {
		proxy: {
			'/api': {
				target: 'http://1.13.187.226:12269/gfs/var',
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, ''),
			}
		}
	},
})
